/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 * 
 * If you have edited the file, please update
 * all the last-modified fields manually. Thanks!
 *
 * @last-modified by: 
 * @last-modified date: 
 * @last-modified time: 
 *
 * @author Swee Zhi
 * @date-created Sep 20, 2011    @time-created 6:56:31 PM
 *
 * @project: 
 * @module: 
 * @institution: 
 *
 */
package temp;

import java.util.ResourceBundle;
import javax.faces.context.FacesContext;

public class WebValidationMessages {
    
    private FacesContext ctx = FacesContext.getCurrentInstance();
    
    public String getValidationMessage(String messageKey)
    {
        String message="";
        
        ResourceBundle validationResources = ResourceBundle.getBundle("ValidationMessages", ctx.getViewRoot().getLocale());
        
        // properties file has this key
        if (validationResources.containsKey(messageKey)) {
            message = validationResources.getString(messageKey);
        }
        // get default value
        else {
           message = validationResources.getString("no.message");
        }

//        //create an instance of properties class
//        Properties props = new Properties();
//
//        //try retrieve data from file
//        //catch exception in case properties file does not exist
//        try {
//            /* test where your glassfish writes file to.. it will read from there as root 
//             * to use testing part, please comment off other parts in the try-catch
//             */
//            
////            File file = new File("findme.properties");
////
////             Create file if it does not exist
////            boolean success = file.createNewFile();
////            if (success) {
////                System.out.println("Successfully created 'findme.properties'");
////                // File did not exist and was created
////                System.out.println(file.getAbsoluteFile());
////                System.out.println(file.getAbsolutePath());
////                System.out.println(file.getCanonicalFile());
////                System.out.println(file.getCanonicalPath());
////            } else {
////                // File already exists
////                System.out.println("'findme.properties' already exists");
////            }
//            /* end test where your glassfish writes file to.. it will read from there as root */
//
//            System.out.println("ValidationMessagesBean: " + locale);
        
        return message;
    }
}
